<?php
/**
 * @author bbernath
 *         Date: 10.11.13
 *         Time: 22:31
 * @version 1.0.0
 */

echo "<h3>Neue News schreiben</h3>";
echo "&laquo; <a href=index.php?action=administration&site=news&userid=" . $_GET['userid'] . ">Zur&uuml;ck zu News verwalten</a><br><br>";
?>

<?php
if (isset($_POST['topic'], $_POST['newstext'], $_GET['userid'])) {
    $insert = "insert into news(topic, content, user, news_category, written) values(?,?,?,?,NOW())";
    if(!$stmt = $db->prepare($insert)) {
        echo $db->error;
    }
    $news_category = 1;
    $newstext = str_replace("\n", "<br>", $_POST['newstext']);
    $stmt->bind_param("ssii", $_POST['topic'], $newstext, $_GET['userid'], $news_category);
    if (!$stmt->execute()) {
        echo $db->error;
    }
    $stmt->close();

    echo "Neue News [".$_POST['topic']."] wurden erfolgreich geschrieben.<br><br>";
    echo "-> <a href=index.php?action=administration&site=news&userid=" . $_GET['userid'] . ">Zur&uuml;ck zu News verwalten</a>";
} else {
    ?>

    <form action='index.php?action=administration&site=add_news&userid=<?php echo $_GET['userid'] ?>' method='post'>
        <table id="news">
            <tr>
                <td><b>&Uumlberschrift:</b></td>
                <td><input name='topic' type='text' size='50' maxlength='50'></td>
            </tr>
            <tr>
                <td><b>Text:</b></td>
                <td><textarea name='newstext' cols='70' rows='18'></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type='submit' value='News absenden'></td>
            </tr>
        </table>
    </form>

<?php
}
?>